home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / ip / EHP / IPF.2 < prev    next >
Encoding:
Text File  |  1990-05-07  |  4.6 KB  |  193 lines

  1. #!/bin/sh
  2. # to extract, remove the header and type "sh filename"
  3. if `test ! -s ./Makefile`
  4. then
  5. echo "writing ./Makefile"
  6. cat > ./Makefile << '\Rogue\Monster\'
  7. #########################################################################
  8. #                                    #
  9. #    Makefile for network datagram test programs.            #
  10. #                                    #
  11. #########################################################################
  12.  
  13. CFLAGS = -gx
  14.  
  15. LIB =
  16.  
  17. BINS = ipforwarding \
  18.  
  19. all: $(BINS)
  20.  
  21. IPFORWARDING_OBJS = \
  22.     ethertoa.o \
  23.     ipforwarding.o \
  24.     nit.o \
  25.     tx_hostname.o
  26.  
  27. ipforwarding: $(IPFORWARDING_OBJS) $(LIB)
  28.     cc -o ipforwarding $(IPFORWARDING_OBJS) $(LIB)
  29.  
  30. .c.o:;    cc $(CFLAGS) -c $<
  31. \Rogue\Monster\
  32. else
  33.   echo "will not overwrite ./Makefile"
  34. fi
  35. if [ `wc -c ./Makefile | awk '{printf $1}'` -ne 478 ]
  36. then
  37. echo `wc -c ./Makefile | awk '{print "Got " $1 ", Expected " 478}'`
  38. fi
  39. if `test ! -s ./ethertoa.3`
  40. then
  41. echo "writing ./ethertoa.3"
  42. cat > ./ethertoa.3 << '\Rogue\Monster\'
  43. .TH ETHERTOA 3 "ISTC" 25-Sep-87
  44. .SH NAME
  45. .nf
  46. atoether \- Translate ascii to ethernet address
  47. ethertoa \- Translate ethernet address to ascii
  48. .fi
  49. .SH ORIGIN
  50. SRI Information Science and Technology Center
  51. .SH SYNOPSIS
  52. .sp
  53. .ft B
  54. .nf
  55. #include <sys/types.h>
  56. #include <netinet/in.h>
  57. #include <netinet/if_ether.h>
  58. .sp
  59. int atoether(a, ea)
  60. char *a;
  61. struct ether_addr *ea;
  62. .sp
  63. extern char *ethertoa(ea)
  64. struct ether_addr *ea;
  65. .SH DESCRIPTION
  66. The `atoether' routine translates the string pointed to by `a' into an
  67. ethernet address, which is placed into the struct pointed to by `ea'.
  68. The string must be in the hexadecimal colon representation.
  69. .LP
  70. The `ethertoa' routine converts the ethernet address pointed to by `ea'
  71. to the ascii hexadecimal colon representation.
  72. Each octet will be zero-padded (if necessary) to two hex digits.
  73. A pointer to the statically stored string will be returned, copy it if
  74. you want to save it across subsequent calls to `ethertoa'.
  75. .SH DIAGNOSTICS
  76. The `atoether' routine will return `1' if the conversion succeeded, `0'
  77. otherwise.
  78. .SH HISTORY
  79. .IP 25-Nov-87 0.75i
  80. Written by Paul E. McKenney, SRI Information Science and Technology Center
  81. \Rogue\Monster\
  82. else
  83.   echo "will not overwrite ./ethertoa.3"
  84. fi
  85. if [ `wc -c ./ethertoa.3 | awk '{printf $1}'` -ne 1156 ]
  86. then
  87. echo `wc -c ./ethertoa.3 | awk '{print "Got " $1 ", Expected " 1156}'`
  88. fi
  89. if `test ! -s ./ethertoa.c`
  90. then
  91. echo "writing ./ethertoa.c"
  92. cat > ./ethertoa.c << '\Rogue\Monster\'
  93. /************************************************************************
  94.  *                                    *
  95.  *    File:  ethertoa.c                        *
  96.  *                                    *
  97.  *    ETHERnet address TO Ascii (and vice versa).            *
  98.  *                                    *
  99.  *    Written 08-Sep-87 by Paul E. McKenney, SRI International.    *
  100.  *                                    *
  101.  ************************************************************************/
  102.  
  103. /*
  104.  *    $Log:    ethertoa.c,v $
  105.  * Revision 2.0  88/09/23  18:27:40  mckenney
  106.  * .
  107.  * 
  108.  */
  109.  
  110. /* Include files.                            */
  111.  
  112. #include <stdio.h>
  113. #include <sys/types.h>
  114. #include <sys/socket.h>
  115. #include <net/if.h>
  116. #include <netinet/in.h>
  117. #include <netinet/if_ether.h>
  118.  
  119. /* Type definitions local to this file.                    */
  120.  
  121. /* Functions exported from this file.                    */
  122.  
  123. extern int        atoether();    /* Ascii TO ETHERnet address.    */
  124. extern char        *ethertoa();    /* ETHERnet address TO Ascii.    */
  125.  
  126. /* Functions local to this file.                    */
  127.  
  128. /* Variables exported from this file.                    */
  129.  
  130. /* Variables local to this file.                    */
  131.  
  132.  
  133. /* Ascii TO ETHERnet address conversion.  Returns TRUE if the string    */
  134. /* can be converted, FALSE otherwise.  Address must be of form:        */
  135. /*    xx:xx:xx:xx:xx:xx                        */
  136.  
  137. int
  138. atoether(a, ea)
  139.  
  140.     char        *a;        /* Ascii address.        */
  141.     struct ether_addr *ea;        /* Ethernet Address.        */
  142.  
  143.     {
  144.     int        o0;
  145.     int        o1;
  146.     int        o2;
  147.     int        o3;
  148.     int        o4;
  149.     int        o5;
  150.  
  151.     if (sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5) != 6)
  152.         return (0);
  153.  
  154.     ea->ether_addr_octet[0] = o0;
  155.     ea->ether_addr_octet[1] = o1;
  156.     ea->ether_addr_octet[2] = o2;
  157.     ea->ether_addr_octet[3] = o3;
  158.     ea->ether_addr_octet[4] = o4;
  159.     ea->ether_addr_octet[5] = o5;
  160.     return (1);
  161.     }
  162.  
  163. /* ETHERnet address TO Ascii conversion.  Note that the returned string    */
  164. /* is kept in a static buffer, so copy it if you want to keep it!    */
  165.  
  166. extern char *
  167. ethertoa(ea)
  168.  
  169.     struct ether_addr *ea;        /* Ethernet Address.        */
  170.  
  171.     {
  172.     static char    addr[25];    /* ascii-ized ADDRess.        */
  173.  
  174.     (void)sprintf(addr, "%02x:%02x:%02x:%02x:%02x:%02x",
  175.               ea->ether_addr_octet[0],
  176.               ea->ether_addr_octet[1],
  177.               ea->ether_addr_octet[2],
  178.               ea->ether_addr_octet[3],
  179.               ea->ether_addr_octet[4],
  180.               ea->ether_addr_octet[5]);
  181.     return (addr);
  182.     }
  183. \Rogue\Monster\
  184. else
  185.   echo "will not overwrite ./ethertoa.c"
  186. fi
  187. if [ `wc -c ./ethertoa.c | awk '{printf $1}'` -ne 2122 ]
  188. then
  189. echo `wc -c ./ethertoa.c | awk '{print "Got " $1 ", Expected " 2122}'`
  190. fi
  191. echo "Finished archive 3 of 3"
  192. exit
  193.